public class l19_删除链表的第N个节点 {

    ListNode listNode =  new ListNode();

    public ListNode removeNthFromEnd(ListNode head, int n) {

        int nownum = 1;
        ListNode nowNode = head;
        ListNode nowt = head;
        while (nowNode.next !=  null){

            if (nownum < n+1)
                nowNode = nowNode.next;
            else {
                nowNode = nowNode.next;
                nowt = nowt.next;
            }


            nownum ++;

        }
        if(nownum == n)
            return head.next;

        nowt.next= nowt.next.next;

        return  head;



    }

}




class ListNode {
     int val;
     ListNode next;
     ListNode() {}
     ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next;
     }
}
